import { inject, onMounted } from "vue"

export const scale = () => {
    let scene
    let drawLine
    let drawPolygon
    let drawCircle
    let drawnElements = []; // 存储所有已绘制的要素的数组
    const { DrawLine, DrawCircle, DrawPolygon, DrawEvent } = L7.Draw
    onMounted(() => {
        scene = inject('$scene')
    })

    const line = () => {
        drawLine = new DrawLine(scene, {
            distanceOptions: {},
        });
        drawLine.enable();

        drawLine.on(DrawEvent.Change, (allFeatures) => {
            drawLine.enabled = false
            drawnElements.push(allFeatures)

        });
    }

    const polygon = () => {
        drawPolygon = new DrawPolygon(scene, {
            areaOptions: {},
        });
        drawPolygon.enable();

        drawPolygon.on(DrawEvent.Change, (allFeatures) => {
            drawPolygon.enabled = false
            drawnElements.push(allFeatures)
        });
    }

    const circle = () => {
        drawCircle = new DrawCircle(scene, {});
        drawCircle.enable();

        drawCircle.on(DrawEvent.Change, (allFeatures) => {
            drawCircle.enabled = false
            drawnElements.push(allFeatures)
        });
    }

    const clear = () => {
        scene.removeAllLayer()
    }

    return {
        line,
        polygon,
        circle,
        clear,
    }
}